package com.ruoyi.web.controller.system;

import java.util.List;
import javax.servlet.http.HttpServletResponse;

import com.ruoyi.system.domain.vo.YgemployeeMap;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.system.domain.YgEmployee;
import com.ruoyi.system.service.IYgEmployeeService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 员工Controller
 * 
 * @author 你虎啊
 * @date 2022-11-24
 */
@RestController
@RequestMapping("/system/employee")
public class YgEmployeeController extends BaseController
{
    @Autowired
    private IYgEmployeeService ygEmployeeService;

    /**
     * 查询员工列表
     */
    @PreAuthorize("@ss.hasPermi('system:employee:list')")
    @GetMapping("/list")
    public TableDataInfo list(YgemployeeMap YgemployeeMap)
    {
        startPage();
        List<YgemployeeMap> list = ygEmployeeService.selectYgEmployeeListt(YgemployeeMap);
//        System.out.println(">>>>>>>>>>>>>"+list.toString());
        return getDataTable(list);
    }

    /**
     * 导出员工列表
     */
    @PreAuthorize("@ss.hasPermi('system:employee:export')")
    @Log(title = "员工", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, YgEmployee ygEmployee)
    {
        List<YgEmployee> list = ygEmployeeService.selectYgEmployeeList(ygEmployee);
        ExcelUtil<YgEmployee> util = new ExcelUtil<YgEmployee>(YgEmployee.class);
        util.exportExcel(response, list, "员工数据");
    }

    /**
     * 获取员工详细信息
     */
    @PreAuthorize("@ss.hasPermi('system:employee:query')")
    @GetMapping(value = "/{empid}")
    public AjaxResult getInfo(@PathVariable("empid") Long empid)
    {
        return success(ygEmployeeService.selectYgEmployeeByEmpid(empid));
    }

    /**
     * 新增员工
     */
    @PreAuthorize("@ss.hasPermi('system:employee:add')")
    @Log(title = "员工", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody YgEmployee ygEmployee)
    {
        return toAjax(ygEmployeeService.insertYgEmployee(ygEmployee));
    }

    /**
     * 修改员工
     */
    @PreAuthorize("@ss.hasPermi('system:employee:edit')")
    @Log(title = "员工", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody YgEmployee ygEmployee)
    {
        return toAjax(ygEmployeeService.updateYgEmployee(ygEmployee));
    }

    /**
     * 删除员工
     */
    @PreAuthorize("@ss.hasPermi('system:employee:remove')")
    @Log(title = "员工", businessType = BusinessType.DELETE)
	@DeleteMapping("/{empids}")
    public AjaxResult remove(@PathVariable Long[] empids)
    {
        return toAjax(ygEmployeeService.deleteYgEmployeeByEmpids(empids));
    }
}
